- Write a C++ program to that computes the area of a triangle using Heron's formula.
- Prompt the user for three inputs that are the lengths of three sides of a triangle.
- Store sides in variables a, b, c
- Compute p = (a + b + c) / 2
- Heron's formula: Area of triangle = sqrt(p*(p-a)*(p-b)*(p-c))
Sample run of program:
Enter lengths of three sides of triangle:
Side 1: 3
Side 2: 4
Side 3: 5
Area of triangle: 6
- Write a complete C++ program that does the following:
- Prompts the user for a number between 5 and 15.
- This number gives the dimensions of a 2D shape, with that number of rows and twice as many columns.
- If the number is invalid, forces the user to enter a valid input.
- Generates two distinct single digit random numbers.
- Have your program check to make sure the two random numbers are not the same.
- Print a border of * around the perimeter, with * in the first and last row, and first and last column. Inside the border, the odd-numbered columns consist of the first randomly generated number, even-numbered columns consist of the second randomly generated number.
Sample run of program:
Enter a number between 5 and 15 (inclusive): 16
Invalid input! Try again: 4
Invalid input! Try again: 6
************
*8484848484*
*8484848484*
*8484848484*
*8484848484*
************
Another sample run of program:
Enter a number between 5 and 15 (inclusive): 5
**********
*73737373*
*73737373*
*73737373*
**********
- Write a complete C++ program that lists all numbers that are perfect squares in a range.
- Generate an int called low that is a random number between 50 and 200.
- Generate a second int called high that is a random number between 700 and 3000.
- Print to the monitor: "The perfect squares between [low] and [high] are:" (where low and high are replaced by the random numbers)
- List all numbers that are perfect squares between low and high.
Sample partial run of program:
The perfect squares between 179 and 1270 are:
196
225
256
289
325
361
400
- Write a complete C++ program that does the following:
- Generates a random number between 2000 and 5000.
- Prints a table containing the following:
- All numbers between 1000 and the randomly generated number that have the property that their square ends in 56
- List each number and its square, separated by a space
Sample partial run of program:
All numbers between 1000 and 2435 whose square ends in 56 are:
1016 squared is 1032256
1034 squared is 1069156
1066 squared is 1136356
1084 squared is 1175056
...
- Write a complete C++ program that plays an adding game.
- Asks the user to solve five random adding problems with two numbers.
- Generate two random numbers each between 1 and 100 (inclusive).
- The question to ask the user is essentially, random_num1 + random_num2 = ?
- Every time the program is run, the random addition questions should be different.
- Print the addition problem to the monitor and read in the answer from the user.
- If the user answers incorrectly (that is, the user's answer is not the correct sum), tell the user what the correct answer was.
- After asking all the questions, tell the user the number answered correctly and the number answered incorrectly.
I will ask you five addition questions. Please enter the sum for each.
4 + 10 = 14
15 + 49 = 54
Wrong! The answer was 64
13 + 72 = 85
64 + 3 = 67
99 + 45 = 145
Wrong! The answer was 144
You got 3 correct, 2 wrong.